package com.chenyue.cm.user.dao.provider;


import com.chenyue.cm.common.utils.StringUtils;
import org.apache.ibatis.jdbc.SQL;



public class JdGoodsSpuProvider {

    public String getHomePageGoodsList(String classifyId, String keyWord){
        return new SQL() {
            {
                SELECT("spu.id as id," +
                        "spu.good_name as goodsName, " +
                        "spu.img_url as imgUrl, " +
                        "spu.integral as integral, "+
                        "spu.exchange as sales, " +
                        "spu.hot_flag as hotFlag ");
                FROM("jd_goods_spu spu  ");
                if (StringUtils.isNotEmpty(classifyId)){
                    WHERE("spu.classify_id = '"+ classifyId+"' ");
                }
                if (StringUtils.isNotEmpty(keyWord)){
                    WHERE("spu.good_name like '%"+ keyWord+"%' ");
                }
                WHERE("spu.state = 1");
                ORDER_BY(" spu.hot_flag  DESC,spu.create_time DESC ");
                // LIMIT(1);
            }
        }.toString();
    }


    public String getHomePageGoodsCount(String classifyId, String keyWord){
        return new SQL() {
            {
                SELECT(" count(0) ");
                FROM("jd_goods_spu spu ");
                if (StringUtils.isNotEmpty(classifyId)){
                    WHERE("spu.classify_id = '"+ classifyId+"' ");
                }
                if (StringUtils.isNotEmpty(keyWord)){
                    WHERE("spu.good_name  like '%"+ keyWord+"%' ");
                }
            }
        }.toString();
    }
}
